# myapp/views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.urls import reverse
from django.shortcuts import redirect
def redirect_to_another_view(request):
    return redirect('index')  # 重定向到名为 'index' 的视图
def dynamic_url_view(request):
    # 使用 reverse 动态获取路由的 URL
    url = reverse('index')  # 假设首页路由名为 'index'
    return render(request, 'myapp/dynamic_link.html', {'url': url})
def index_view(request):
    return render(request,'myapp/index.html')

def hello_view(request):
    return HttpResponse("Hello, Django!")

def add_view(request, a, b):
    result = a + b
    return HttpResponse(f"The sum is: {result}")

def post_view(request, num):
    return HttpResponse(f"You accessed post-{num}.")
